import ModifyPassword from './modify-password.vue'
import Vue from 'vue'

let instance
const ModifyInstanceConstructor = {
    init () {
        instance = instance || new Vue({
            data () {
                return {
                    value: false
                }
            },
            render (h) {
                return h(ModifyPassword, {
                    props: {
                        value: this.value
                    },
                    on: {
                        input: v => {
                            this.value = v
                        }
                    }
                })
            },
            close () {
                this.value = false
            }
        }).$mount()
        document.body.appendChild(instance.$el)
    },
    open () {
        if (instance) {
            instance.value = true
        } else {
            this.init()
            instance.value = true
        }
    },
    destroy () {
        if (instance) {
            document.body.removeChild(instance.$el)
            instance.$destroy()
        }
    }
}

export default ModifyInstanceConstructor
